/****************************************
Table 2
*****************************************/

* Load Data
use "$dir/Data/Final/Isonymy_fs", clear

drop if pre == 0

collapse ///
         (mean) IsoObs_f = IsoObs_fs  IsoNonrand_f = IsoNonrand_fs IsoRand_f = IsoRand_fs ///
		 (rawsum) N_f = N_fs [aw = N_fs], by(surname)
		 
gen cm = 4*max(0, IsoNonrand_f)	
		 
* Number of isonymous marriages
gen N_i = round(IsoObs_f*N_f)

* Label vars
keep surname IsoObs_f IsoRand_f IsoNonrand_f cm N_f N_i
label var surname "Surname"
label var IsoObs_f "Observed Isonymy"
label var IsoRand_f "Random Isonymy"
label var IsoNonrand_f "Non-random Isonymy"
label var cm "Cousin Marriage rate"
label var N_f "Individuals with surname"
label var N_i "Married to same surname spouse"

* Keep randomly chosen surnames
keep if inlist(surname,  "smith", "wallace", "goff", "swan")
outsheet surname IsoRand_f IsoNonrand_f IsoObs_f N_f cm N_i using "$dir/Output/TablesFigures/IsoCM.csv", comma replace
